package com.shanzmoo.core.domain.pay;

import com.shanzmoo.base.constant.PayStatusConstant;
import com.shanzmoo.base.constant.e.PayTypeEnum;
import com.shanzmoo.base.constant.e.WxTradeTypeEnum;
import com.shanzmoo.db.trade.entity.PayOrderEntity;
import com.shanzmoo.base.util.BillNoUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * 微信网页支付请求信息
 *
 * @author Gzhao 2021/1/2
 */
@Data
@ApiModel("微信网页支付请求信息")
public class PayOrderByWxJsapReq implements Serializable {

    private static final long serialVersionUID = 1758L;

    @NotBlank
    @ApiModelProperty(value = "订单号", example = "MA202101022353489219")
    private String orderNo;

    @NotBlank
    @ApiModelProperty(value = "订单(商品)描述", example = "测试订单")
    private String describe;

    @NotNull
    @ApiModelProperty(value = "标价金额(分)", example = "1")
    private Integer totalFee;

    @NotBlank
    @ApiModelProperty(value = "用户IP", example = "123.12.12.123")
    private String ip;

    @NotBlank(message = "微信JSAPI支付，用户标识不允许为空")
    @ApiModelProperty(value = "用户标识", example = "odEwj6iFngZXqD9gHOsww9oYjTe8")
    private String openid;

    public PayOrderEntity convertToPayOrderEntity() {

        return PayOrderEntity.builder()
                .type(PayTypeEnum.Wx.getCode())
                .payNo(BillNoUtils.generatePayNo())
                .orderNo(orderNo)
                .payStatus(PayStatusConstant.WAIT_PAY)
                .body(describe)
                .totalFee(totalFee)
                .ip(ip)
                .tradeType(WxTradeTypeEnum.JSAPI.getDesc())
                .build();

    }

}
